﻿<?php
include("mysql.php");

$image_id = $_POST['id'];
$last_text_id = $_POST['message'];

//get all the messages
$query = sprintf("SELECT text,timestamp FROM messages m JOIN images i ON (m.img_id = i.id) WHERE i.id = '%s'",
mysql_real_escape_string($image_id));
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
	$message  = 'Invalid query: ' . mysql_error() . "\n";
	$message .= 'Whole query: ' . $query;
	mysql_close();
	die($message);
}
print(json_encode("FEEDBACK_START"));
$count = 1;
while($row = mysql_fetch_array($result))
{
	if($count > $last_text_id){
		$output = "FEEDBACK_MSG_TEXT".$row['timestamp'].": ".$row['text'];
		print(json_encode($output));
	}
	$count++;
}

mysql_close();
?>